﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.ObjectModel;

/// <summary>
/// Summary description for Helpers
/// </summary>
public class Helpers
{

    /// <summary>
    /// This is a method to popululate the DropDownList'
    /// with the items from the CsvItems enumeration
    /// </summary>
    /// <param name="ddl">DropDownList ti populate
    /// </param>
    public static void PopulateDropDown(DropDownList ddl, Type enm)
    {
        ddl.Items.Clear();
        //create our Collection<strng> to hold the ddl items
        //then set that varu=iable to theLoadCsvTypes Functuin
        //in the Utilities ckas
        Collection<string> csv = LoadEnums(enm);
        //now loop though all the items in our collection
        for (int i = 0; i < csv.Count; i++)
        {
            //addeach item to the list
            ListItem item = new ListItem(csv[i].ToString(), csv[i].ToString());
            ddl.Items.Add(item);
        }
        //now we need to adda{SelectIne]" option at
        //the beginning of the list
    }

    public static Collection<String> LoadEnums(Type enm)
    {
        Collection<String> str = new Collection<string>();
        //get the names from the enumeration
        string[] names = Enum.GetNames(enm);
        //Now we loop through all the names in the enum list
        //looking for a match
        for (int i = 0; i <= names.Length - 1; i++)
        {
            str.Add(names[i].ToString());
        }
        return str;
    }
}
